using Microsoft.EntityFrameworkCore;
using System.Windows.Forms;
using Table_pet.background;
using Table_pet.background.Classes;
using Newtonsoft.Json;
using Table_pet.cache;
using System.Text;
using Table_pet.Response;
using ChatUI;
using ClockUI;

namespace Table_pet
{
    internal static class Program
    {
        public static void setGlobal()
        {
            if (File.Exists(".\\cache.json"))
            {
                string buffer = string.Empty;
                using (FileStream fs = new FileStream(".\\cache.json", FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
                    {
                        buffer = sr.ReadToEnd().ToString();
                    }
                }
                dynamic json = JsonConvert.DeserializeObject(buffer);
                Memorandum.id = json.lastID;
                ClockModel.id = json.ClocklastID;
            }
            else
            {
                Memorandum.id = 1;
                ClockModel.id = 1;
            }
        }
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            setGlobal();
            string requestBody = JsonConvert.SerializeObject(new Cache(1,2));
            File.WriteAllText(".//cache.json", requestBody);

            //WEB_api wEB_Api = new WEB_api();
            /*  wEB_Api.chat();*/
           
            ApplicationConfiguration.Initialize();
            Application.Run(new Form1());
            
            //Application.Run(new MemorandumList());
            //chatform
            //Application.Run(new chatform());
           
           
        }
    }
}